﻿using System.Text;

namespace Universe.MediaProbe
{
    using System.Globalization;

    public class Converter
    {
        public ConvertOptions Options { get; set; }

        public string GetHumanCommandLine(string source)
        {
            // ffmpeg -i "R:\Four-Rooms.mkv" -strict experimental -vcodec copy -acodec aac -ab 256K -ac 3 "C:\Four-Rooms-IV.mp4"
            string ao =
                !Options.NeedAudioConvert
                    ? @"-acodec copy"
                    : string.Format(
                        @"-acodec aac -ab {0} -ac {1} -af volume={2}",
                        Options.AudioBitRate + "K", 
                        Options.AudioChannels, 
                        (Options.AudioVolume/100m).ToString("f2", CultureInfo.InvariantCulture)
                        );

            string vo =
                !Options.NeedVideoConvert
                    ? "-vcodec copy"
                    : string.Format("-vcodec {1} -b:v {0}K", Options.VideoBitRate, Options.VideoCodec);

            StringBuilder streams = new StringBuilder();
            if (Options.IdStreamList != null)
                foreach (var i in Options.IdStreamList)
                    streams.Append(streams.Length == 0 ? "" : " ").Append("-map 0:").Append(i);
            
/*
            return
                string.Format(
                    @"-i ""{0}"" -map 0:0 -map 0:{3} -strict experimental {1} {2} ""{0}.mp4""",
                    source, ao, vo,
                    Options.IdAudioStream);
*/
            return
                string.Format(
                    @"-i ""{0}"" -map 0:0 {3} -strict experimental {1} -scodec mov_text {2} {4} ""{0}{5}""",
                    source, ao, vo,
                    streams,
                    Options.Optional,
                    Options.Container ?? ".mp4");

        }
    }
}
